﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace BattleThis.Core
{
	/// <summary>
	/// Represent a position in the game map.
	/// </summary>
	[System.Diagnostics.DebuggerDisplay( "Column {Column}, Row {Row}" )]
	public class Position
	{

		#region Variablen
		/// <summary>
		/// A position wich is not defined.
		/// </summary>
		public static readonly Position Undefined = new Position();
		#endregion

		#region Properties

		/// <summary>
		/// Gets or sets the row-index-position.
		/// </summary>
		/// <value>
		/// The row.
		/// </value>
		public int Row { get; set; }

		/// <summary>
		/// Gets or sets the column-index-position.
		/// </summary>
		/// <value>
		/// The column.
		/// </value>
		public int Column { get; set; }

		/// <summary>
		/// Determines whether this instance is even.
		/// </summary>
		/// <returns>
		///   <c>true</c> if this instance is even; otherwise, <c>false</c>.
		/// </returns>
		public bool IsEven()
		{
			return this.Column % 2 == 0;
		}
		#endregion

		#region Methoden
		/// <summary>
		/// Prevents a default instance of the <see cref="Position"/> class from being created.
		/// </summary>
		private Position()
		{
			this.Column = -1;
			this.Row = -1;
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="Position"/> class.
		/// </summary>
		/// <param name="column">The column.</param>
		/// <param name="row">The row.</param>
		public Position( int column, int row )
		{
			this.Column = column;
			this.Row = row;
		}

		/// <summary>
		/// Determines whether this instance is empty.
		/// </summary>
		/// <returns>
		///   <c>true</c> if this instance is empty; otherwise, <c>false</c>.
		/// </returns>
		public bool IsUndefined()
		{
			return this.Equals( Undefined );
		}

		/// <summary>
		/// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
		/// </summary>
		/// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param>
		/// <returns>
		///   <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
		/// </returns>
		public override bool Equals( object obj )
		{
			if( !( obj is Position ) ) return false;

			var toCompare = (Position)obj;

			return this.Row.Equals( toCompare.Row ) && this.Column.Equals( toCompare.Column );
		}

		/// <summary>
		/// Equalses the specified row.
		/// </summary>
		/// <param name="row">The row.</param>
		/// <param name="column">The column.</param>
		/// <returns></returns>
		public bool Equals( int row, int column )
		{
			return this.Row.Equals( row ) && this.Column.Equals( column );
		}

		/// <summary>
		/// Returns a hash code for this instance.
		/// </summary>
		/// <returns>
		/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. 
		/// </returns>
		public override int GetHashCode()
		{
			return this.Row.GetHashCode() ^ this.Column.GetHashCode();
		}

		/// <summary>
		/// Returns a <see cref="System.String"/> that represents this instance.
		/// </summary>
		/// <returns>
		/// A <see cref="System.String"/> that represents this instance.
		/// </returns>
		public override string ToString()
		{
			return string.Format( "Column {0}, Row {1},", this.Column, this.Row );
		}

		/// <summary>
		/// Toes the short string.
		/// </summary>
		/// <returns></returns>
		public string ToShortString()
		{
			return string.Format( "{0}_{1}", this.Column, this.Row );
		}
		#endregion


	}
}